package longrise.phone.com.bjjt_henan.lunchandlogin;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.baidu.mobstat.StatService;
import com.longrise.bjjt.util.PrefUtils;

import longrise.phone.com.bjjt_henan.MainActivity;
import longrise.phone.com.bjjt_henan.R;

public class SplashActivity extends Activity {

    private static final int TIME = 3000;

    int count = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
                | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        super.onCreate(savedInstanceState);
        StatService.start(this);//百度无埋点统计
        setContentView(R.layout.activity_splash);
        setVersion();
        count = PrefUtils.getInt(this, "appcount", 0);
        count++;
        PrefUtils.setInt(this, "appcount", count);
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                Intent intent = new Intent();
                if (count == 1) {
                    intent.setClass(SplashActivity.this, GuidActivity.class);
                } else {
                    intent.setClass(SplashActivity.this, MainActivity.class);
                }
                SplashActivity.this.startActivity(intent);
                overridePendingTransition(R.anim.transition_to_anim, R.anim.transition_in_anim);
                SplashActivity.this.finish();

            }
        }, TIME);
    }

    private void setVersion() {
        try {
            TextView versionTV = (TextView) findViewById(R.id.splash_tv_version);
            PackageManager pm = this.getPackageManager();
            if (null != pm) {
                PackageInfo packageInfo = pm.getPackageInfo(this.getPackageName(), 0);
                if (null != packageInfo) {
                    versionTV.setText(packageInfo.versionName);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
